package entity.immobile;

import java.awt.geom.Line2D;
import java.awt.geom.Point2D;

import loading.ImageLoader;
import main.GameList;
import entity.Entity;
import entity.item.Key;

public class Door extends Entity implements Solid
{
	private Key key;
	public Door(Point2D pos, GameList game, ImageLoader img, Key key) 
	{
		super(pos, game, img);
		this.key = key;
		setCircular(false);
	}
	//unlocks the door, essentially removing it
	public void unlock()
	{
		getGameList().remove(this);
	}
	public Key getKey() 
	{
		return key;
	}
	
	
	public int getCollisionSide(Entity ent)
	{
		//get the two points on the top side
		Point2D.Double point = new Point2D.Double(getPosition().getX()+getImage().width(), getPosition().getY());
		Line2D.Double side = new Line2D.Double(getPosition(), point);
		if (Math.abs(side.ptSegDist(ent.getPosition())) < ent.getRadius())
			return 0;
		//get the two points on the right side
		point = new Point2D.Double(getPosition().getX()+getImage().width(), getPosition().getY());
		Point2D.Double point2 = new Point2D.Double(point.getX(), point.getY()+getImage().height());
		side = new Line2D.Double(point, point2);
		if (Math.abs(side.ptSegDist(ent.getPosition())) < ent.getRadius())
			return 1;
		//get the two points on the bottom side
		point = new Point2D.Double(getPosition().getX(), point2.getY());
		side = new Line2D.Double(point, point2);
		if (Math.abs(side.ptSegDist(ent.getPosition())) < ent.getRadius())
			return 2;
		//get the two points on the left side
		side = new Line2D.Double(point, getPosition());
		if (Math.abs(side.ptSegDist(ent.getPosition())) < ent.getRadius())
			return 3;
		else
			return -1;
	}
}
